//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "Garch11.h"
using namespace Cephei::QL::Models::Volatility;
#include <gen/QL/VolatilityCompositor.h>
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (Double a, Double b, Double vl) : CVolatilityCompositor(CGarch11::typeid)
{
    try
    {
#ifdef HANDLE
        _phGarch11 = NULL;
#endif
        QuantLib::Real _a = (QuantLib::Real)ValueHelper::Convert (a);
        QuantLib::Real _b = (QuantLib::Real)ValueHelper::Convert (b);
        QuantLib::Real _vl = (QuantLib::Real)ValueHelper::Convert (vl);
        _ppGarch11 = new boost::shared_ptr<QuantLib::Garch11> (new QuantLib::Garch11 ( _a,  _b,  _vl ));
        SetVolatilityCompositor (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (boost::shared_ptr<QuantLib::Garch11>& childNative, Object^ owner) : CVolatilityCompositor(CGarch11::typeid)
{
#ifdef HANDLE
	_phGarch11 = NULL;
#endif
	_ppGarch11 = &childNative;
    _ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
}
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (QuantLib::Garch11& childNative, Object^ owner) : CVolatilityCompositor(CGarch11::typeid)
{
#ifdef HANDLE
	_phGarch11 = NULL;
#endif
	_ppGarch11 = new boost::shared_ptr<QuantLib::Garch11> (&childNative);
    _ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
    _Garch11Owner = owner;
    _VolatilityCompositorOwner = owner;
}

Cephei::QL::Models::Volatility::CGarch11::CGarch11 (CGarch11^ copy) : CVolatilityCompositor(CGarch11::typeid)
{
#ifdef HANDLE
	_phGarch11 = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGarch11 = new boost::shared_ptr<QuantLib::Garch11> (copy->GetShared());
        _ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
    }
}
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (System::Type^ t) : CVolatilityCompositor(CGarch11::typeid)
{
#ifdef HANDLE
	_phGarch11 = NULL;
#endif
	if (!t->IsSubclassOf(CGarch11::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (QuantLib::Handle<QuantLib::Garch11>& childNative, Object^ owner)  : CVolatilityCompositor(CGarch11::typeid)
{
	_phGarch11 = &childNative;
	_ppGarch11 = &static_cast<boost::shared_ptr<QuantLib::Garch11>>(childNative.currentLink());
    _ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
    _Garch11Owner = owner;
}
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (QuantLib::Handle<QuantLib::Garch11> childNative)  : CVolatilityCompositor(CGarch11::typeid)
{
	_phGarch11 = &childNative;
	_ppGarch11 = &static_cast<boost::shared_ptr<QuantLib::Garch11>>(childNative.currentLink());
    _ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Volatility::CGarch11::CGarch11 (QuantLib::Garch11 childNative)  : CVolatilityCompositor(CGarch11::typeid)
{
#ifdef HANDLE
	_phGarch11 = NULL;
#endif
	_ppGarch11 = new boost::shared_ptr<QuantLib::Garch11> (new QuantLib::Garch11 (childNative));
    _ppVolatilityCompositor = new boost::shared_ptr<QuantLib::VolatilityCompositor> (boost::dynamic_pointer_cast<QuantLib::VolatilityCompositor> (*_ppGarch11));
}
#endif

Cephei::QL::Models::Volatility::CGarch11::~CGarch11 ()
{
    if (_ppGarch11 != NULL)
    {
	    delete _ppGarch11;
        _ppGarch11 = NULL;
    }
}
Cephei::QL::Models::Volatility::CGarch11::!CGarch11 ()
{
    if (_ppGarch11 != NULL)
    {
	    delete _ppGarch11;
    }
}
QuantLib::Garch11& Cephei::QL::Models::Volatility::CGarch11::GetReference ()
{
    if (_ppGarch11 == NULL) throw gcnew NativeNullException ();
	return **_ppGarch11;
}
boost::shared_ptr<QuantLib::Garch11>& Cephei::QL::Models::Volatility::CGarch11::GetShared ()
{
    if (_ppGarch11 == NULL) throw gcnew NativeNullException ();
	return *_ppGarch11;
}
QuantLib::Garch11* Cephei::QL::Models::Volatility::CGarch11::GetPointer ()
{
    if (_ppGarch11 == NULL) throw gcnew NativeNullException ();
	return &**_ppGarch11;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Garch11>& Cephei::QL::Models::Volatility::CGarch11::GetHandle ()
{
	if (_phGarch11 == NULL)
	{
		_phGarch11 = new Handle<QuantLib::Garch11> (*_ppGarch11);
	}
	return *_phGarch11;
}
#endif
bool Cephei::QL::Models::Volatility::CGarch11::HasNative () 
{
	return (_ppGarch11 != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Models::Volatility::IGarch11^ Cephei::QL::Models::Volatility::CGarch11_Factory::Create (Double a, Double b, Double vl)
{
    return gcnew CGarch11 ( a,  b,  vl);
}
